package apis

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"mini-gde/pkg"
	"mini-gde/service"
)

// GetContainers 容器列表
func GetContainers(c *gin.Context) {
	containers := service.GetContainers()
	c.JSON(http.StatusOK, gin.H{
		"code": pkg.SUCCESS,
		"msg":  pkg.GetMsg(pkg.SUCCESS),
		"data": containers,
	})
}

// StartContainer 启动容器
func StartContainer(c *gin.Context) {
	containerId := c.Param("id")

	service.StartContainer(containerId)
	c.JSON(http.StatusOK, gin.H{
		"code": pkg.SUCCESS,
		"msg":  pkg.GetMsg(pkg.SUCCESS),
	})
}

// StopContainer 停止容器
func StopContainer(c *gin.Context) {
	containerId := c.Param("id")

	service.StopContainer(containerId)
	c.JSON(http.StatusOK, gin.H{
		"code": pkg.SUCCESS,
		"msg":  pkg.GetMsg(pkg.SUCCESS),
	})
}
